package com.hongye.why.module;

import android.content.Intent;
import android.content.pm.PackageManager;
import android.widget.Toast;

import com.hongye.why.MainActivity;
import com.hongye.why.app.AppManager;
import com.hongye.why.R;
import com.hongye.why.app.UpdateManager;
import com.hongye.why.base.BaseActivity;
import com.hongye.why.base.TaskPool;
import com.igexin.sdk.PushManager;

/**
 * 欢迎页activity
 */
public class LaunchActivity extends BaseActivity {

    @Override
    public int inflateLayout() {
        return R.layout.activity_launch;
    }

    @Override
    public void onCreate() {
        PushManager.getInstance().initialize(getApplicationContext());

        showTitle(false);

        TaskPool.myPool().postTaskOnMainDelay(new Runnable() {
            @Override
            public void run() {
                if (AppManager.getManager().getUserSession().hasLogged()) {
                    Intent intent = new Intent(LaunchActivity.this, MainActivity.class);
                    startActivity(intent);
                } else {
                    Intent intent = new Intent(LaunchActivity.this, LoginActivity.class);
                    startActivity(intent);
                }
                finish();
            }
        }, 2000);

        try {
            int versionCode = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;
            UpdateManager.updateManager().checkVersion(versionCode);
        } catch (PackageManager.NameNotFoundException e) {
            Toast.makeText(this, "获取版本号失败", Toast.LENGTH_SHORT).show();
        }
    }
}
